let rateparams = {}

function getImplementationRate() {
	rateparams = {
		username: getUsername,
		budgetYear: localStorage.getItem("year"),
		budgetMonth: localStorage.getItem("month"),
		budgetNo: localStorage.getItem("budgetNo"),
		status: 2,
		chartPage: 70402,
		chartNo: 1
	}
	$.get(
		`${API_URL}getdata`, {
			...rateparams
		},
		function(res) {
			let re = eval("(" + res + ")");
			console.log(re)
			let data = re.items[0].charts[0].data[0];
			if(data){
				$('#rateMask .mask-scroll .left').html(`<div class="budget">
								<h4>${data.key04}预算总额</h4>
								<h2>${FormatWYCash(data.key01)}<span>万元</span></h2>
							</div>
							<div class="execute">
								<h5>执行总额</h5>
								<h3>${FormatWYCash(data.key02)}<span>万元</span></h3>
							</div>
							<div class="execute">
								<h5>执行率</h5>
								<h3>${(data.key03*100).toFixed(2)}%</h3>
								<div class="process">
								    <div class="process-data" style="width: ${data.key03*100}%;"></div>
								    <span class="process-flag"></span>
								</div>
							</div>`)
			}
		})
	$.get(
		`${API_URL}getdata`, {
			...rateparams,
			chartNo: 2
			
		},
		function(res) {
			let re = eval("(" + res + ")");
			console.log(re)
			getMonPayComplete(re.items[0].charts[0].data)
		})


	getratestate()
}

function getratestate() {
	$.get(
		`${API_URL}getdata`, {
			...rateparams,
			chartNo: 3
			
		},
		function(res) {
			let re = eval("(" + res + ")");
			console.log(re)
			if (re.items[0].charts[0].data.length > 0) {
				$('#rateMask .mask-scroll .state p').html(`${re.items[0].charts[0].data[0].key01}`)
			}
		})
}

$('.mask-wrap .btn button.save').click(function() {
	$.get(
		`${API_URL}getdata`, {
			...rateparams,
			chartNo: 4,
			key01:$('.mask-wrap .mask-write-area textarea').val()
		},
		function(res) {
			let re = eval("(" + res + ")");
			$('#editMask').hide()
			alert(re.items[0].charts[0].chart_name)
			getratestate()
		})
})



//月度到款执行
function getMonPayComplete(data) {
	let xData = [];
	let currYearTotal = [];
	let currYearBudget = [];
	let increase = [];
	let legendData = ["预算金额", "执行金额", "执行率"];

	for (var i = 0; i < data.length; i++) {
		xData.push(+data[i].key01);
		currYearTotal.push((data[i].key02 / 10000).toFixed(2));
		currYearBudget.push((data[i].key03 / 10000).toFixed(2));
		increase.push((data[i].key04 * 100).toFixed(2));
	}

	let Data = [{
			name: "预算金额",
			type: "bar",
			barWidth: "25",
			barGap: 0,
			itemStyle: {
				color: "#165DFF",
			},
			data: currYearTotal,
		},
		{
			name: "执行金额",
			type: "bar",
			barWidth: "25",
			barGap: 0,
			itemStyle: {
				color: "#50CD89",
			},
			data: currYearBudget,
		},
		{
			name: "执行率",
			type: "line",
			barWidth: "13",
			barGap: 0,
			yAxisIndex: 1,
			itemStyle: {
				color: "#7239EA",
			},
			data: increase,
		},
	];

	have("monthlj") ? mulitYBar("monthlj", xData, legendData, Data) : "";
}
